package com.meilai.project.mapper.business.contract;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.meilai.project.entity.business.contract.ContractNum;
import org.apache.ibatis.annotations.*;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xchen
 * @since 2022-03-24
 */
@Mapper
public interface ContractNumMapper extends BaseMapper<ContractNum> {
	@Select("select count(*) from contract_num where type = #{type} and years = #{years}")
	boolean hasExists(@Param("type") String type, @Param("years") String year);

	@Insert(" insert into contract_num(type,years,curr_num) values (#{type},#{years},0) " +
			" on duplicate key update curr_num=curr_num ")
	void init(@Param("type") String type, @Param("years") String year);

	@Select(" select * from contract_num where type = #{type} and years = #{years} for update")
	ContractNum lock(@Param("type") String type, @Param("years") String year);

	@Update("update contract_num set curr_num = curr_num + 1 where type = #{type} and years = #{years} ")
	void increase(@Param("type") String type, @Param("years") String year);

	@Select("select curr_num from contract_num where type = #{type} and years = #{years} ")
	Integer getCurrNum(@Param("type") String type, @Param("years") String year);

}
